package com.thingcom.delinrobot.main.Launch.NewUser;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.gizwits.gizwifisdk.api.GizUserInfo;
import com.gizwits.gizwifisdk.api.GizWifiSDK;
import com.gizwits.gizwifisdk.enumration.GizUserAccountType;
import com.gizwits.gizwifisdk.enumration.GizWifiErrorCode;
import com.gizwits.gizwifisdk.listener.GizWifiSDKListener;
import com.thingcom.delinrobot.Common.Constant;
import com.thingcom.delinrobot.R;
import com.thingcom.delinrobot.base.BaseBackFragment;
import com.thingcom.delinrobot.main.adddevice.DeviceListActivity;
import com.thingcom.delinrobot.utils.MyLog;
import com.thingcom.delinrobot.utils.PreferencesUtil;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * author : YuFeng
 * e-mail : 923462992@qq.com
 * date   : 2019/12/4
 */
public class RegisterSuccessFragment extends BaseBackFragment {

    @BindView(R.id.btn_register_success)
    Button btnRegisterSuccess;

    public static RegisterSuccessFragment newInstance() {
        Bundle args = new Bundle();
        RegisterSuccessFragment fragment = new RegisterSuccessFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_back_register_success, container, false);
        unbinder = ButterKnife.bind(this, view);
        String token = PreferencesUtil.getInstance(getContext()).getString(Constant.TOKEN, null);
        GizWifiSDK.sharedInstance().setListener(mListener);
        GizUserInfo gizUserInfo = new GizUserInfo();
        String name = PreferencesUtil.getInstance(getContext()).getString(Constant.USER_NAME,null);
        String address = PreferencesUtil.getInstance(getContext()).getString(Constant.CHOOSE_COUNTRY,null);
        MyLog.i("用户信息", "onCreateView: "+"name:"+name+"address:"+address);
        gizUserInfo.setName(name);
        gizUserInfo.setAddress(address);
        GizWifiSDK.sharedInstance().changeUserInfo(token,null,null,GizUserAccountType.GizUserNormal,gizUserInfo);
        return view;
    }

    private GizWifiSDKListener mListener = new GizWifiSDKListener() {
        @Override
        public void didChangeUserInfo(GizWifiErrorCode result) {
        }
    };

    @OnClick({ R.id.btn_register_success})
    public void onViewClicked(View view) {
        //            case R.id.tv_register_success:
        //                Intent intent = new Intent(getContext(), DeviceListActivity.class);
        //                startActivity(intent);
        //                break;
        if (view.getId() == R.id.btn_register_success) {//               start(AddDeviceZeroFragment.newInstance());
            Intent intent = new Intent(getContext(), DeviceListActivity.class);
            startActivity(intent);
        }
    }
}
